package cn.linpq.menu;
import cn.linpq.frame.MineFrame;
import cn.linpq.util.Tools;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Desc : 帮助菜单类
 * ClassName : cn.linpq.menu.HelpMenu
 * @author : 林鹏群
 * @date : 2022/12/12 11:29
 */
public class HelpMenu extends JMenu {
    private MineFrame mineFrame;
    public HelpMenu(MineFrame mineFrame){
        this.setText("帮助");
        this.mineFrame = mineFrame;
        //初始化`版权`菜单
        JMenuItem copyRight = new JMenuItem("版权");
        JMenuItem cheat = new JMenuItem("大胆作弊");
        JMenuItem flag = new JMenuItem("偷偷作弊");
        //添加`版权`菜单
        this.add(copyRight);
        this.add(cheat);
        this.add(flag);
        //绑定`版权`菜单ActionListener事件
        copyRight.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(null,"林鹏群开发，亲情定制！");
            }
        });
        cheat.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                for (int i = 0; i < Tools.rows; i++) {
                    for (int j = 0; j < Tools.cols; j++) {
                        if (mineFrame.getMineField().getMineLabels()[i][j].isMine()){
                            mineFrame.getMineField().getMineLabels()[i][j].setIcon(Tools.hole);
                        }
                    }
                }
            }
        });

        flag.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                for (int i = 0; i < Tools.rows; i++) {
                    for (int j = 0; j < Tools.cols; j++) {
                        if (mineFrame.getMineField().getMineLabels()[i][j].isMine()){
                            mineFrame.getMineField().getMineLabels()[i][j].setFlag(true);
                        }
                    }
                }
            }
        });
    }
}
